/*
 * 作者:熊猫
 * 日期:2017 - 3 - 19 9 - 34 - 39
 *
 */

package net.lainiao.morethread.Chapter7.demo8;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.AbstractQueuedSynchronizer;

/**
 * Created by Administrator on 2017/3/19.
 */
public class MyAbstractQueueSynchornizer extends AbstractQueuedSynchronizer {
    private AtomicInteger state;

    public MyAbstractQueueSynchornizer() {
        state = new AtomicInteger(0);
    }

    @Override
    protected boolean tryAcquire(int arg) {
        return state.compareAndSet(0,1);
    }

    @Override
    protected boolean tryRelease(int arg) {
        return state.compareAndSet(1,0);
    }
}
